#pragma once

#include "MyPage.h"
#include "MyVideoWidget.h"
#include "VideoPlayList.h"

#include <QWidget>
#include <QToolBar>
#include <QMediaPlayer>
#include <QAction>
#include <QMenu>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QSlider>
#include <QListWidget>
#include <QToolBar>
#include <QAudioOutput>
#include <QComboBox>

class MyVideoWidget;

/**
 * @brief The VideoPage class
 * 视频页面
 */
class VideoPage : public MyPage
{
	Q_OBJECT

public:
	VideoPage();

	QWidget* getWidget();

private Q_SLOTS:
	void positionSliderMoved(int value);
	void positionSliderRangeChanged(int min, int max);
	void playerPositionChanged(qint64 value);
	void playerDurationChanged(qint64 value);
	void positionSliderValueChanged(int value);
	void volumeSliderMoved(int value);
	void volumeSliderValueChanged(int value);
	void playerSourceChanged(QUrl url);
	void playerRateChanged(qreal spd);
	void audioOutputChanged(int indx);
	void playListDoubleClicked(QListWidgetItem *item);
	void playNext();
	void playPrevious();

public Q_SLOTS:
	void setPlaySource(QUrl url);

	void goHome();

	void openFile();

	void pausePlayer();
	void startPlayer();
	void stopPlayer();
	void enablePlayerFullScreen();
	void disablePlayerFullScreen();
	void skipForward();
	void skipBackward();
	void playSpeedUp();
	void playSpeedDown();
	void closeVolume();
	void openVolume();
	void togglePlay();
	void updateToggleIcon();

	void switchPlayList();
	void playListChanged();
	void currentIndexChanged(int index);

private:
	void setupUI();
	void createAction();
	void createMenu();
	void createToolBar();

	QToolBar *toolbar;
	QMediaPlayer *player;
	MyVideoWidget *videoWidget;
	QAudioOutput *audioOutput;

	QMenu *playMenu;

	QAction *goHomeAction;
	QAction *openFileAction;

	QAction *pausePlayAction;
	QAction *startPlayAction;
	QAction *stopPlayAction;
	QAction *enableFullScreenAction;
	QAction *disableFullScreenAction;
	QAction *skipForwardAction;
	QAction *skipBackwardAction;
	QAction *playSpeedUpAction;
	QAction *playSpeedDownAction;
	QAction *closeVolumeAction;
	QAction *openVolumeAction;
	QAction *switchPlayListAction;
	QAction *playNextAction;
	QAction *playPreviousAction;
	QAction *togglePlayAction;

	QVBoxLayout *vLayout_1, *vLayout_2, *vLayout_3;
	QHBoxLayout *hLayout_1, *hLayout_2, *hLayout_3, *hLayout_4;

	QLabel *currentPositionLabel;
	QLabel *totalPositionLabel;
	QLabel *volumeLabel;
	QLabel *videoNameLabel;
	QLabel *playSpeedLabel;

	QSlider *positionSlider;
	QSlider *volumeSlider;

	QComboBox *audioOutputComboBox;

	QToolBar *playControlBar;
	QToolBar *volumeControlBar;
	QToolBar *headBar;

	QPushButton *backToMainButton;

	QListWidget *playListWidget;
	QWidget *playListBox;

	qreal previousVolume;

	VideoPlayList playList;
};

